<?php 
	
	include "../../config.php";
	require_once DOC_ROOT."lib/connection.php";
	include ADMIN_ROOT."templates/header.php";
	include ADMIN_ROOT."templates/left.php";	
?>

<div class="main-content">
	<?php
		if(!$_POST){
			$id =  $_GET["id"];
			$stmt= sqlsrv_query($con,"SELECT * FROM users WHERE user_id=?",array($id));
			if($row = sqlsrv_fetch($stmt)){
				include ADMIN_ROOT."views/edit.php";			
			}
		}
		else{
			$id = $_POST['id'];
			$fname= $_POST['txtfname'];
			$lname=$_POST['txtlname'];
			$email=$_POST['email'];
			$name= $_POST['txtName'];
			$pass= $_POST['txtPass'];
			
			$con = sqlsrv_connect(SERVER,$conInfo);
			$stmt = sqlsrv_query($con,"UPDATE users SET first_name=?,last_name=?,email=?,user_name=?,password=? WHERE id=?",array(
			$fname,$lname,$email,$name,$pass,$id));
			header("location:index.php");
			
		}
	?>
</div>
<?php	
	include ADMIN_ROOT."templates/footer.php";	
?>
